<?php
 
 class __module_user extends __module_user_api {

  	var $ver    = "1";
	var $urls   = array(		// This list pages in module. array( "default" => "default_page_name", "namepage" => "nameclass" )
					"default"	  => "def",
					
					"def"		  => "page_default",
					"login"		  => "page_login",
					"logout"          => "page_logout",
					
					"block_login" => "block_login"
				);
	
	function page_default($args=array()) {
 		
 	}
	
	function page_login($args=array()) {
		if(isset($_POST['login']) && !empty($_POST['login']) && isset($_POST['passwd']) && !empty($_POST['passwd']) ) {
			if(self::login($_POST['login'], $_POST['passwd'])) {
				save_session_now();
				__kernel_api::redirect('/');
			} else {
				__driver_display::si()->assign('user_error', '1');
				save_session_now();
				return __driver_display::si()->fetch(array('page_login.tpl', new KT_start_moduleName('user')));
			}
		} else {
			__driver_display::si()->assign('user_error', '0');
			save_session_now();
			return __driver_display::si()->fetch(array('page_login.tpl', new KT_start_moduleName('user')));
		}
	}
	
	function page_logout($args=array()) {
	        unset($_SESSION['user']);
	        
	        save_session_now();
	        __kernel_api::redirect('/');
	}
	
	function block_login() {
		global $init;
		
		if($_SESSION['user']['id']) return false;
		
		return array(
                'body'=>__driver_display::si()-> fetch(array('blocks/login.tpl', new KT_start_moduleName('user'))),
				'title'  => $GLOBALS['languages']['user']['block_login_title']
		);
	}
 }
?>
